class Maraphon:
    def __init__(self):
        self.start_num = 0

    def get_input(self):
        rec_numbers = {"one": "1", "two": "2", "three": "3", "four": "4", "five": "5", "six": "6", "seven": "7",
                       "eight": "8", "nine": "9",
                       "zero": "0"}
        input_nums = input().split()
        for str_num in input_nums:
            if str_num.isdigit():
                print("Wrong input")
                break
            if str_num not in rec_numbers:
                print("Wrong input")
                break
        else:
            if len(input_nums) == 3:

                new_num = int(rec_numbers[input_nums[0]] + rec_numbers[input_nums[1]] + rec_numbers[input_nums[2]])
                if len(str(new_num)) != 3:
                    print("Wrong input")
                else:
                    self.start_num = new_num
            else:
                print("Wrong input")

    def is_prime(self, a):
        if a % 2 == 0:
            return a == 2
        d = 3
        while d * d <= a and a % d != 0:
            d += 2
        return d * d > a

    def find_easy_num(self):
        if self.start_num != 0:
            if self.is_prime(self.start_num):
                print(self.start_num)
            else:
                append_id = 0
                first_test = 0

                while append_id < 100:
                    append_id += 1
                    if self.is_prime(append_id + self.start_num):
                        first_test = append_id + self.start_num
                        break

                append_id = 0
                second_test = 0

                while append_id < 100:
                    append_id += 1
                    if self.is_prime(self.start_num - append_id):
                        second_test = self.start_num - append_id
                        break

                check_first = first_test - self.start_num
                check_second = self.start_num - second_test

                if check_second == check_first:
                    print(min(first_test, second_test))
                elif check_second > check_first:
                    print(first_test)
                elif check_second < check_first:
                    print(second_test)


programm = Maraphon()
programm.get_input()
programm.find_easy_num()
